﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bitcoin.Test.TestData;
using NUnit.Framework;

namespace Bitcoin.Test
{
    [TestFixture]
    public class BitcoinSecretTest
    {
        private static readonly ChainParameters _testParams = ChainParameters.TestNet();
        private static readonly ChainParameters _prodParams = ChainParameters.ProdNet();

        [Test]
        [TestCaseSource(typeof(Base58KeysInvalidData))]
        public void TestInvalid(string base58)
        {
            bool isValid = false;
            try
            {
                var key = new BitcoinSecret(null, base58);
                isValid = key.IsValid(_testParams);
            }
            catch (AddressFormatException ex)
            {
                Console.WriteLine("Exception: {0}", ex);
            }

            Assert.IsFalse(isValid);
        }

        [Test]
        [TestCaseSource(typeof(Base58KeysValidPrivateData))]
        public void TestValid(string base58, byte[] bytes, bool isTestNet)
        {
            bool isValid = false;
            var key = new BitcoinSecret(null, base58);
            if (isTestNet)
            {
                isValid = key.IsValid(_testParams);
            }
            else
            {
                isValid = key.IsValid(_prodParams);
            }

            Assert.IsTrue(isValid);
        }

    }
}
